<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/main.css" />
    <script type="text/javascript" src="../script/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="../script/api.js"></script>
    <script type="text/javascript" src="../script/mobile.js"></script>
    <script type="text/javascript" src="../script/public.js"></script>

    <script src="../script/laydate_plus/laydate.js"></script>
    <script type="text/javascript" src="../script/app.js"></script>
    <title>选择订餐日期</title>
</head>
<body>
<header>
    <div class="xiaomaib">
        <div>
            <img src="../image/jiant_rg.png" alt="" onclick="payback()">
            <p>选择订餐日期</p>
        </div>
        
    </div>
</header>
<div class="testView"></div>

<div class="infs_tij">
    <input type="button" value="确定" onclick="payment()">
    <input type="hidden" name="datescheck" />
    <input type="hidden" name="dates" />
</div>
</body>
<script>

    $(function () {

        $(function () {

            $(".laydate-day-mark").parents("td").css("background","none");
        })


        //格式化日期：yyyy-MM-dd
        function formatDate(date) { 
            var myyear = date.getFullYear(); 
            var mymonth = date.getMonth()+1; 
            var myweekday = date.getDate(); 

            if(mymonth < 10){ 
            mymonth = "0" + mymonth; 
            } 
            if(myweekday < 10){ 
            myweekday = "0" + myweekday; 
            } 
            return (myyear+"-"+mymonth + "-" + myweekday); 
        } 

        
        var now = new Date(); //当前日期 

        var nowDayOfWeek = now.getDay(); //今天本周的第几天
        var nowDay = now.getDate(); //当前日
        var nowMonth = now.getMonth(); //当前月
        var nowYear = now.getFullYear(); //当前年

        $('input[name=datescheck]').val(nowYear+'-'+(nowMonth+1)+'-'+nowDay);


        nowYear += (nowYear < 2000) ? 1900 : 0; //

        var weekStartDate = new Date(nowYear, nowMonth, nowDay);//当前的年月日
        var start_week = formatDate(weekStartDate); 

        var weekEndDate = new Date(nowYear, nowMonth, nowDay + (6 - nowDayOfWeek)); 
        var end_week = formatDate(weekEndDate); 

       // alert(start_week+','+end_week);
       var time = '';

       apiready = function () {
        $api.fixStatusBar($api.dom('.header'));
        api.addEventListener({
            name: 'keyback'
        }, function(ret, err){
            api.closeWidget();
        }); 

         var params = api.pageParam;  //获取参数

         $('input[name=dates]').val(params.dates);


        q = {uid:id};
        api.ajax({
            url:webSiteUrl+'/App/Record/selected',
            method:'post',
            data:{
                values:q
            }
        },function(ret,err){
           
            if(ret.code == 200){
               //alert(ret.data.length);
                var marks = {};
                var len = ret.data.length;
                if(len > 0){


                    for(var i=0;i<len;i++){
                        var daytitle = '';
                        for(var j=0;j<ret.data[i].info.length;j++){

                            daytitle += "<li>"+ret.data[i].info[j].dc_name+"</li>";

                        }

                        marks[ret.data[i].dc_time] = "<p id='data_num'>"+parseInt(ret.data[i].dc_day)+"</p><ul id='data_dao'>"+daytitle+"</ul>";

                    }

                    
                }

                laydate.render({
                    elem: '.testView'
                    ,position: 'static'
                    //,mark:marks
                    ,change: function(value, date){ //监听日期被切换
                        
                    },min: start_week
                    ,max:7
                    ,mark: marks
                    ,showBottom: false
                    ,done: function(value, date){

                        $('input[name=datescheck]').val(value);
                        /*if(date.year === 2018 && date.month === 7 && date.date === 25){ //点击2017年8月15日，弹出提示语
                           /!* alert('');*!/
                        }*/
                    }
                }); 


            }else{

                laydate.render({
                    elem: '.testView'
                    ,position: 'static'
                    ,change: function(value, date){ //监听日期被切换
                    },min: start_week
                    ,max: 7
                    ,showBottom: false
                    ,mark: time
                    ,done: function(value, date){

                        $('input[name=datescheck]').val(value);
                        /*if(date.year === 2018 && date.month === 7 && date.date === 25){ //点击2017年8月15日，弹出提示语
                           /!* alert('');*!/
                        }*/
                    }
                }); 

            }
        });
    }
        
       // var time = {'2018-12-11': '<p id="data_num">16</p><ul id="data_dao"><li>早餐</li><li>午餐</li><li>123</li></ul>'}

        
    })
</script>
<script type="text/javascript">
    window['adaptive'].desinWidth = 750;
    window['adaptive'].baseFont = 28;
    window['adaptive'].maxWidth = 750;
    window['adaptive'].init();

    apiready = function () {
        $api.fixStatusBar($api.dom('.header'));
        api.addEventListener({
            name: 'keyback'
        }, function(ret, err){
            api.closeWidget();
        }); 

         var params = api.pageParam;  //获取参数

         $('input[name=dates]').val(params.dates);
    }
    

    //确定日期
        function payment(){
            var data = $('input[name=dates]').val();
            var check = $('input[name=datescheck]').val();

            var day = new Date(check).getDay();
            if (day == 0 || day == 6) {
                alert('请选择工作日订餐');return false;
            }

            if(data == ''){

                var listdate = check;

            }else{
                var listdate = data+','+check;

                if($.inArray(check,data.split(',')) >= 0){

                    alert('您已经选择过当前日期');return false;

                }

            }

             api.openWin({
                name: 'dcdate',
                url: './dingcan.html',
                reload:true,
                pageParam: {
                    dates: listdate
                }
            });


        }

        //返回
        function payback(){
            var data = $('input[name=dates]').val();

             api.openWin({
                name: 'dcdate',
                url: './dingcan.html',
                reload:true,
                pageParam: {
                    dates: data
                }
            });


        }
</script>
</html>